package com.system.healthproject.model.admin.controller;

import com.system.healthproject.bean.*;
import com.system.healthproject.common.ApiResult;
import com.system.healthproject.model.admin.paramsbean.IllDiscussInfo;
import com.system.healthproject.model.admin.service.PatientActivityService;
import com.system.healthproject.pojo.Doctor;
import com.system.healthproject.pojo.PatientActivity;
import com.system.healthproject.utils.DateUtils;
import com.system.healthproject.utils.SimpleFormatutiles;
import io.swagger.annotations.*;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * @author Xuheng Zhou
 * @date 2020/6/8 10:59
 * @desc
 */

@Controller
@RequestMapping("/admin/patientActivity")
@Api(value = "后台患教模块",tags = "后端-患教管理API")
public class PatientActivityController {

    @Autowired
    private PatientActivityService service;


    /**
     * 查询一个患教信息详情
     * @param patientactivityId
     * @return
     */
    @ApiOperation(value = "查询患教信息详情接口(已调试)",notes = "查询某个患教详情信息",httpMethod = "post")
    @RequestMapping(value = "/selectOnePatientActivity",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiImplicitParam(name = "patientactivityId",value = "患教活动id",dataType = "String",required = true)
    public ApiResult<PatientActivityOneBean> selectOnePatientActivity(@RequestParam Integer patientactivityId){

        System.out.println(patientactivityId);

        PatientActivityOneBean patientActivityOneBean=new PatientActivityOneBean();
        patientActivityOneBean= service.selectPatientActivityById(patientactivityId);

        return ApiResult.successWithData("查询成功",patientActivityOneBean);
    }


    /**
     * 多条件查询患教信息
     * @param selectPatientActivityBean
     * @return
     */
    @ApiOperation(value = "多条件查询患教信息接口（已调试）",notes = "多条件查询患教详情信息",httpMethod = "post")
    @RequestMapping(value = "/selectPatientActivityWhere",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public ApiResult<PagesBean<PatientActivityResultBean>> selectPatientActivityWhere( @RequestBody selectPatientActivityBean selectPatientActivityBean){

        List<PatientActivityResultBean> list=new ArrayList<>();

        list=service.selectPatientActivity(selectPatientActivityBean);
        Integer count=service.selectPatientActivityCount(selectPatientActivityBean);
        PagesBean pagesBean=new PagesBean();
        pagesBean.setData(list);
        pagesBean.setPageSize(selectPatientActivityBean.getSize());
        //因为查询所有数据的时候，实体类的引用传递，实体类的page值已经改变了，page已经减1，传回前端，就需要加1。
        pagesBean.setNowsPage(selectPatientActivityBean.getPage()+1);
        pagesBean.setDataCount(count);

        return ApiResult.successWithData("查询成功",pagesBean);
    }


    /**
     * 新增患教信息
     * @param patientActivityBean
     * @return
     */
    @ApiOperation(value = "患教信息新增接口（已调试）",notes = "新增患教信息",httpMethod = "post")
    @RequestMapping(value = "/insertPatientActivity",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public ApiResult insertPatientActivity(@RequestBody PatientActivityBean patientActivityBean) {

        System.out.println(patientActivityBean);
        boolean tf=service.insertPatientActivity(patientActivityBean);
        ApiResult apiResult=new ApiResult();
        if(tf){
            apiResult.setMsg("添加成功");
        }
        return apiResult;

    }

    /**
     * 取消患教活动
     * @param patientactivityId
     * @param cancelreason
     * @return
     */
    @ApiOperation(value = "取消患教活动接口（已调试）",notes = "取消患教信息",httpMethod = "post")
    @RequestMapping(value = "/cancelPatientActivity",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "patientactivityId",value = "患教活动id",dataType = "String",required = true),
            @ApiImplicitParam(name = "cancelreason",value = "取消理由",dataType = "String",required = true)
    })
    public ApiResult cancelPatientActivity(@RequestParam(name = "patientactivityId") Integer patientactivityId,
                                        @RequestParam(name = "cancelreason") String cancelreason) {

        System.out.println(cancelreason+"---"+patientactivityId);
        //修改,取消理由，和状态为 已取消1
        boolean tf=service.cancelPatientActivity(patientactivityId,cancelreason);
        ApiResult apiResult=new ApiResult();
        if (tf){
            apiResult.setCode(200);
            apiResult.setMsg("取消成功");
        }else {
            apiResult.setCode(500);
            apiResult.setMsg("取消失败！请检查选择活动是否正确");
        }
        return apiResult;


    }

    /**
     * 编辑患教信息
     * @param updatePatientActivityOneBean
     * @return
     */
    @ApiOperation(value = "患教信息编辑接口（已调试）",notes = "编辑患教信息",httpMethod = "post")
    @RequestMapping(value = "/updatePatientActivity",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public ApiResult updatePatientActivity(@RequestBody UpdatePatientActivityOneBean updatePatientActivityOneBean) {


        System.out.println(updatePatientActivityOneBean);
        boolean tf=service.updatePatientActivity(updatePatientActivityOneBean);
        ApiResult apiResult=new ApiResult();
        if(tf){
            apiResult.setMsg("编辑成功");
        }
        return apiResult;

    }


    /**
     * 查询患教活动报名信息
     * @param page
     * @param size
     * @return
     */
    @ApiOperation(value = "患教活动报名信息查询接口（已调试）",notes = "查询所有的患教报名信息",httpMethod = "post")
    @RequestMapping(value = "/selectPatientActivitySignUp",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "patientActivityId",value = "患教活动id",dataType = "Integer"),
            @ApiImplicitParam(name = "page",value = "当前页数",dataType = "Integer"),
            @ApiImplicitParam(name = "size",value = "页数显示数据条数",dataType = "Integer")})
    @ResponseBody
    public ApiResult<PagesBean<PatientActivitySignUpBean>> selectPatientActivitySignUp(@RequestParam(name = "patientActivityId") Integer patientActivityId,
                                                                                       @RequestParam(name = "page") Integer page ,
                                                                                       @RequestParam(name = "size") Integer size){

        System.out.println(patientActivityId);

        List<PatientActivitySignUpBean> list=new ArrayList<>();

        list=service.selectPatientActivitySignUp(patientActivityId,page,size);

        Integer count=service.selectPatientActivitySignUpCount(patientActivityId,page,size);

        PagesBean pagesBean=new PagesBean();
        pagesBean.setDataCount(count);
        pagesBean.setData(list);
        pagesBean.setNowsPage(page);
        pagesBean.setPageSize(size);

        return ApiResult.successWithData("查询成功",pagesBean);
    }

    /**
     * 根据医生id进行查询患教活动
     * @param doctorId
     * @param page
     * @param size
     * @return
     */

    @ApiOperation(value = "根据医生id查询该医生的患教信息接口（已调试）",notes = "查询医生的患教信息",httpMethod = "post")
    @RequestMapping(value = "/selectDoctorPatientActivityByDoctorId",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "doctorId",value = "医生id",dataType = "Integer"),
            @ApiImplicitParam(name = "page",value = "当前页数",dataType = "Integer"),
            @ApiImplicitParam(name = "size",value = "页数显示数据条数",dataType = "Integer")})
    public ApiResult<PagesBean<selectPatientActivityByDoctorIdBean>> selectDoctorPatientActivityByDoctorId(@RequestParam("doctorId") Integer doctorId,
                                                                                                 @RequestParam(name = "page") Integer page ,
                                                                                                 @RequestParam(name = "size") Integer size){

        List<selectPatientActivityByDoctorIdBean> list=service.selectDoctorPatientActivityByDoctorId(doctorId,page,size);
        //获取患教的总条数
        Integer count=service.selectPatientActivityCountByDoctorId(doctorId);
        PagesBean pagesBean=new PagesBean();
        pagesBean.setData(list);
        pagesBean.setPageSize(size);
        pagesBean.setNowsPage(page);
        pagesBean.setDataCount(count);
        return ApiResult.successWithData("查询成功",pagesBean);
    }


    @ApiOperation(value = "删除患教活动信息接口(已调试)",notes = "删除患教活动信息",httpMethod = "post")
    @RequestMapping(value = "/deletePatientActivity",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiImplicitParam(name = "patientactivityId",value = "患教活动id",dataType = "String",required = true)
    public ApiResult deletePatientActivity(@RequestParam Integer patientactivityId){

        System.out.println(patientactivityId);

        boolean tf=service.deletePatientActivityById(patientactivityId);

        ApiResult apiResult=new ApiResult();
        if (tf) {
            apiResult.setMsg("删除患教活动成功");
            apiResult.setCode(200);
        }else {
            apiResult.setMsg("删除患教活动失败");
            apiResult.setCode(500);
        }

        return apiResult;
    }

}
